<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Cache;
use App\Models\ad;
class AdCategory extends Model
{
   protected $guarded=[];
    function ads(){
        $this->hasMany('App\Models\Ad','category_id');
    }

    static function get_categories(){
        $categories = Cache::rememberForever('lxmall_ad_categories', function () {
            return self::orderBy('sort_order')->get();
        });

        return $categories;
    }

    static function check_ads($id){
        $category=self::with('ads')->find($id);
        if($category->ads->isEmpty()){
            return true;
        }
        return false;
    }
    
}
